# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: thefatprecious <marty@loomar.com>

pkgname=tvtime
pkgver=1.0.11
pkgrel=4
pkgdesc="High quality television application for use with video capture cards"
arch=('loong64' 'x86_64')
url='https://linuxtv.org/'
license=('GPL')
depends=('alsa-lib' 'freetype2' 'hicolor-icon-theme' 'libxinerama' 'libxml2' 'libxss' 'libxv' 'libxxf86vm')
makedepends=('imagemagick')
source=("https://linuxtv.org/downloads/$pkgname/$pkgname-$pkgver.tar.gz"
        "tvtime-icon-100x100.png::https://git.linuxtv.org/tvtime.git/plain/docs/tvtime-icon-100x100.png?id=v$pkgver"
        freetype.patch
        0001-Fix-warning-implicit-declaration-of-function-minor-m.patch
        0001-Fix-AppStream-metadata-validation.patch)
sha256sums=('403bf2106578b1f3d6ce70bc08654f7a90753f19e27b4cc170bc636307cdc78c'
            'b6342cebcf981f3e2119c36e74403d2b4f6f73910fc4b84925a1df038ddc37f1'
            'a29e800114d35c5b2bec24b637fb6ac861f1f2246ecf1437fe4aaab6df6eb040'
            '11dfd5b00554a304bde8b7a31ec15c6a3bf320b83d607e17c4e327dc7b36ad12'
            '40f7c01dadcc8521ac3ce9cbc269829868383396f4c511a47538bccf9b5952f4')

prepare() {
  cd $pkgname-$pkgver

  # Fix build
  patch -Np1 -i ../0001-Fix-warning-implicit-declaration-of-function-minor-m.patch
  patch -Np1 -i ../freetype.patch

  # Fix AppStream metadata
  patch -Np1 -i ../0001-Fix-AppStream-metadata-validation.patch
  sed -i 's|$(datadir)/appdata|$(datadir)/metainfo|' docs/Makefile.{am,in}

  autoreconf -fi
}

build() {
  cd $pkgname-$pkgver
  ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
  make
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  install -Dm644 docs/html/default.tvtime.xml "$pkgdir"/usr/share/tvtime/default.tvtime.xml
  install -dm755 "$pkgdir"/usr/share/icons/hicolor/{64x64,96x96}/apps/
  convert ../tvtime-icon-100x100.png +set date:create +set date:modify -resize 64x64 -alpha on "$pkgdir/usr/share/icons/hicolor/64x64/apps/tvtime.png"
  convert ../tvtime-icon-100x100.png +set date:create +set date:modify -resize 96x96 -alpha on "$pkgdir/usr/share/icons/hicolor/96x96/apps/tvtime.png"
}
